package com.java.algorithm;

/**
 * 由数组实现的栈
 * @param <E>
 *     栈是一种后进先出（LIFO）的线性数据结构
 */

public class ArrayStack<E> implements Stack<E> {
    private ArrayList data;
    public ArrayStack(){
        this(10);
    }
    public ArrayStack(int capacity){
        data=new ArrayList(capacity);
    }
    @Override
    public int getSize() {
        return data.getSize();
    }

    @Override
    public boolean isEmpty() {
        return data.getSize()==0;
    }

    @Override
    public void push(E e) {
       data.addLast(e);
    }

    @Override
    public E pop() {
        return (E) data.removeLast();
    }

    @Override
    public E peek() {
        return (E) data.getLast();
    }
}
